<?php

/**
 * 公共方法，cache,当第二个参数为''时判定为获取，需要设置这些特殊值的时候使用getCache与setCache函数进行进一步的设置
 * createby kuoqi at 2022/8/16 23:20
 * @param $cname
 * @param string $cval
 * @param string $ctime
 * @param string $cpath
 * @return mixed|null|string
 */
function cache($cname,$cval = '',$ctime = '0',$cpath = '')
{
    return \Kuoqi\Helper::Cache($cname,$cval,$ctime,$cpath);
}

/**
 * 获取缓存
 * createby kuoqi at 2022/8/16 23:24
 * @param $cname
 * @param string $cpath
 * @param bool $isCommon
 * @return mixed|null
 */
function getCache($cname,$cpath = '',$isCommon = false){
    return \Kuoqi\Helper::getCache($cname,$cpath,$isCommon);
}

/**
 * 设置缓存
 * createby kuoqi at 2022/8/16 23:24
 * @param $cname
 * @param string $cval
 * @param string $ctime
 * @param string $cpath
 * @param bool $isCommon
 * @return string
 */
function setCache($cname,$cval = '',$ctime = '0',$cpath = '',$isCommon = false){
    return \Kuoqi\Helper::setCache($cname,$cval,$ctime,$cpath,$isCommon);
}


/**
 * 检测是否wap
 * @return bool|string
 */
function check_wap(){
    if(stristr(@$_SERVER['HTTP_VIA'],"wap")){
        return true;
    }elseif(strpos(strtoupper(@$_SERVER['HTTP_ACCEPT']),"VND.WAP.WML") > 0){
        return true;
    }elseif(preg_match('/(blackberry|configuration\/cldc|hp |hp-|htc |htc_|htc-|iemobile|kindle|midp|mmp|motorola|mobile|nokia|opera mini|opera |Googlebot-Mobile|YahooSeeker\/M1A1-R2D2|android|iphone|ipod|mobi|palm|palmos|pocket|portalmmm|ppc;|smartphone|sonyericsson|sqh|spv|symbian|treo|up.browser|up.link|vodafone|windows ce|xda |xda_)/i', $_SERVER['HTTP_USER_AGENT'])){
        if(preg_match('/MicroMessenger/',$_SERVER['HTTP_USER_AGENT'])){
            return 'wx';
        }
        return true;
    }else
    {
        return false;
    }
}
/**
 * @param string $isPrefix
 * @param bool $dateTable
 * @return \Kuoqi\DbDriver\PdoDriver
 * User kuoqi
 * Datetime 2022/2/28 19:05
 * Remark 基础方法，同助手函数\Kuoqi\Helper::Mysql
 */
function m($isPrefix = '',$dateTable = false)
{
    return \Kuoqi\Helper::Mysql($isPrefix,$dateTable);
}

/**
 * @param $mdName
 * @param string $mdType
 * @return null
 * User kuoqi
 * Datetime 2022/2/28 22:53
 * Remark model模型分为几类，一种是【数据库模型model】,【逻辑模型Service】...等自定义模型
 */
function model($mdName,$mdType = 'Model'){
    return \Kuoqi\Helper::model($mdName,$mdType);
}

/**
 * @param $route
 * @param array $extparams
 * @param bool $isComplex
 * @param bool $isQuerryParms
 * @return mixed
 * User kuoqi
 * Datetime 2022/2/28 23:13
 * Remark url
 */
function url($route,$extparams = array(),$isComplex = false,$isQuerryParms = false){
    return \Kuoqi\Helper::url($route,$extparams,$isComplex,$isQuerryParms);
}

/**
 * @param $n
 * @param null $v
 * @return mixed|null|void
 * User kuoqi
 * Datetime 2022/3/1 16:51
 * Remark 获取或者设置config参数
 */
function config($n,$v = null){
    return \Kuoqi\Helper::config($n,$v);
}

/**
 * 获取参数信息
 * @param string $param
 * @param null $default
 * @param null $delFunc
 * @param bool $isOpt
 * @return null|string
 * @throws \Kuoqi\Error
 */
function I($param = '',$default = NULL,$delFunc = NULL,$isOpt = false)
{
    return \Kuoqi\Helper::getParam($param,$default,$delFunc,$isOpt);
}
//尝试获取用户的IP
function ipfClient()
{
    $IPaddress='';
    if(isset($_SERVER)){
        if(isset($_SERVER["HTTP_X_FORWARDED_FOR"])){
            $IPaddress = $_SERVER["HTTP_X_FORWARDED_FOR"];
        }else if(isset($_SERVER["HTTP_CLIENT_IP"])){
            $IPaddress = $_SERVER["HTTP_CLIENT_IP"];
        }else{
            $IPaddress = $_SERVER["REMOTE_ADDR"];
        }
    }else{
        if(getenv("HTTP_X_FORWARDED_FOR")){
            $IPaddress = getenv("HTTP_X_FORWARDED_FOR");
        }else if(getenv("HTTP_CLIENT_IP")) {
            $IPaddress = getenv("HTTP_CLIENT_IP");
        }else{
            $IPaddress = getenv("REMOTE_ADDR");
        }
    }
    return $IPaddress;
}

/**
 * 原样输出的函数
 * @param bool $str
 * @return bool
 */
function kong($str = false){
    return $str;
}
/**
 * @param $tkDatas
 * @return string
 * User kuoqi
 * Datetime 2022/3/3 14:17
 * Remark token创建
 */
function tokenCreate($tkDatas){
    return \Kuoqi\Helper::tokenCreate($tkDatas);
}

/**
 * @param $tkname
 * @return mixed
 * User kuoqi
 * Datetime 2022/3/3 14:17
 * Remark token读取
 */
function tokenRead($tkname){
    return \Kuoqi\Helper::tokenRead($tkname);
}

/**
 * @param $tkname
 * @return bool|void
 * User kuoqi
 * Datetime 2022/3/3 14:17
 * Remark token销毁
 */
function tokenDestroy($tkname){
    return \Kuoqi\Helper::tokenDestroy($tkname);
}


//其它，，待写入的方法们//
function dump($rs){
	echo '<pre>';
	echo print_r($rs,true);
	echo '</pre>';
}
//转换为密码
function password_encode($str){
	return \Kuoqi\Helper::password_encode($str);
}

function session($sn,$sv = null){
	return \Kuoqi\Helper::session($sn,$sv);
}

//模型
function template($tpid,$tp_agrs = array()){
	return \Kuoqi\Helper::useTemplate($tpid,$tp_agrs);
}



//公共兼容方法
if(!function_exists('lcfirst')){
	function lcfirst($str){
		//单词首字母小写
	}	
}
if(!function_exists('http_response_code')){
	function http_response_code($code = 200){
		//处理响应code的兼容
		
	}	
}
if(!function_exists('output')){
	function output($stream,$code,$type = ''){
		if(is_object($stream)){
			if(property_exists($stream,$code)){
				if($type=='conts'){
					return htmlspecialchars_decode($stream->$code);
				}else{
					return $stream->$code;
				}
			}else{
				return '';
			}
		}else{
			throw new \Kuoqi\Error('没做');
		}
			
	}	
}
//判定是否子数组
if(!function_exists('sub_array')){
	function sub_array($subarr = array(),$allarr = array()){
		foreach($subarr as $item){
			if(!in_array($item,$allarr)){return false;}	
		}	
		return true;
	}	
}
